package hxy.bytecode.date.time;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class UnixTimeTest {
    public static void main(String[] args) {

        Date date = new Date(System.currentTimeMillis());
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        OffsetDateTime odt = OffsetDateTime.now(zoneId);
        ZoneOffset zoneOffset = odt.getOffset();
        LocalDateTime ldt = instant.atOffset(zoneOffset).toLocalDateTime();
//        准确显示本地时间 2020-05-21 20:14:48  HH 大写是24小时制 hh 小写是12小时制
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(zoneId);
        String startTimeStr = ldt.format(dtf);
        System.out.println(startTimeStr);

    }
}
